<template>
    <div class="app-container">
<!--        <el-form :model="queryParams" ref="queryRef" size="small"  :inline="true" v-show="showSearch" label-width="68px">-->
<!--            <el-form-item label="标题" prop="title">-->
<!--                <el-input-->
<!--                        v-model="queryParams.title"-->
<!--                        placeholder="请输入标题"-->
<!--                        clearable-->
<!--                        @keyup.enter.native="handleQuery"-->
<!--                />-->
<!--            </el-form-item>-->
<!--            <el-form-item label="状态" prop="state">-->
<!--              <el-select-->
<!--                v-model="queryParams.state"-->
<!--                placeholder="请选择钱包到账状态"-->
<!--                clearable-->
<!--              >-->
<!--                <el-option-->
<!--                  v-for="dict in dict.type.wallet_state"-->
<!--                  :key="dict.value"-->
<!--                  :label="dict.label"-->
<!--                  :value="dict.value"-->
<!--                />-->
<!--              </el-select>-->
<!--            </el-form-item>-->
<!--            <el-form-item label="钱包途径" prop="classify">-->
<!--              <el-select-->
<!--                v-model="queryParams.classify"-->
<!--                placeholder="请选择钱包来源途径"-->
<!--                clearable-->
<!--              >-->
<!--                <el-option-->
<!--                  v-for="dict in dict.type.wallet_classify"-->
<!--                  :key="dict.value"-->
<!--                  :label="dict.label"-->
<!--                  :value="dict.value"-->
<!--                />-->
<!--              </el-select>-->
<!--            </el-form-item>-->
<!--            <el-form-item>-->
<!--                <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>-->
<!--                <el-button icon="Refresh" @click="resetQuery">重置</el-button>-->
<!--            </el-form-item>-->
<!--        </el-form>-->

        <el-row :gutter="10" class="mb8">
<!--            <el-col :span="1.5">-->
<!--                <el-button-->
<!--                        type="primary"-->
<!--                        plain-->
<!--                        icon="Plus"-->
<!--                        @click="handleAdd"-->
<!--                        v-hasPermi="['web:moneyItem:add']"-->
<!--                >新增</el-button>-->
<!--            </el-col>-->
<!--            <el-col :span="1.5">-->
<!--                <el-button-->
<!--                        type="success"-->
<!--                        plain-->
<!--                        icon="Edit"-->
<!--                        :disabled="single"-->
<!--                        @click="handleUpdate"-->
<!--                        v-hasPermi="['web:moneyItem:edit']"-->
<!--                >修改</el-button>-->
<!--            </el-col>-->
<!--            <el-col :span="1.5">-->
<!--                <el-button-->
<!--                        type="danger"-->
<!--                        plain-->
<!--                        icon="Delete"-->
<!--                        :disabled="multiple"-->
<!--                        @click="handleDelete"-->
<!--                        v-hasPermi="['web:moneyItem:remove']"-->
<!--                >删除</el-button>-->
<!--            </el-col>-->
<!--            <el-col :span="1.5">-->
<!--                <el-button-->
<!--                        type="warning"-->
<!--                        plain-->
<!--                        icon="Download"-->
<!--                        @click="handleExport"-->
<!--                        v-hasPermi="['web:moneyItem:export']"-->
<!--                >导出</el-button>-->
<!--            </el-col>-->
            <right-toolbar :search="false" v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>

        <el-table v-loading="loading" :data="moneyItemList">
<!--            <el-table-column type="selection" width="55" align="center" />-->
<!--        <el-table-column label="明细ID" align="center" prop="itemId" v-if="true"/>-->
<!--        <el-table-column label="对象ID" align="center" prop="objId" />-->
            <el-table-column label="标题" align="center" prop="title" />
<!--            <el-table-column label="工单号" align="center" prop="orderId" width="170">-->
<!--              <template slot-scope="scope">-->
<!--                <router-link :to="'/gongdan/data/index/' + scope.row.orderId" class="link-type">-->
<!--                  <span style="color: #1890ff">{{scope.row.orderId}}</span>-->
<!--                </router-link>-->
<!--              </template>-->
<!--            </el-table-column>-->
            <el-table-column label="收款方" align="center" prop="objName" width="120" />
            <el-table-column label="来源" align="center" prop="type">
              <template slot-scope="scope">
                <dict-tag :options="dict.type.wallet_type" :value="scope.row.type"/>
              </template>
            </el-table-column>
            <el-table-column label="交易方式" align="center" prop="classify">
              <template slot-scope="scope">
                <dict-tag :options="dict.type.wallet_classify" :value="scope.row.classify"/>
              </template>
            </el-table-column>
          <el-table-column label="金额(元)" align="center" prop="money">
            <template slot-scope="scope">
              <span>{{parseFloat(scope.row.money)}}</span>
            </template>
          </el-table-column>
            <el-table-column label="状态" align="center" prop="state">
              <template slot-scope="scope">
                <dict-tag :options="dict.type.wallet_state" :value="scope.row.state"/>
              </template>
            </el-table-column>
          <el-table-column label="内容" align="center" prop="content" width="200"/>
          <el-table-column label="创建时间" align="center" sortable prop="createTime" width="180"/>
<!--                <template slot-scope="scope">-->
<!--                    <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>-->
<!--                </template>-->
<!--            </el-table-column>-->

<!--            <el-table-column label="关联ID" align="center" prop="relationId" />-->
            <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                <template slot-scope="scope">
                    <el-button
                            type="text"
                            icon="Edit"
                            @click="handleUpdate(scope.row)"
                            v-hasPermi="['web:moneyItem:edit']"
                    >处理</el-button>
<!--                    <el-button-->
<!--                            type="text"-->
<!--                            icon="Delete"-->
<!--                            @click="handleDelete(scope.row)"-->
<!--                            v-hasPermi="['web:moneyItem:remove']"-->
<!--                    >删除</el-button>-->
                </template>
            </el-table-column>
        </el-table>

        <pagination
                v-show="total>0"
                :total="total"
                :page.sync="queryParams.pageNum"
                :limit.sync="queryParams.pageSize"
                @pagination="getList"
        />

        <!-- 添加或修改钱包明细对话框 -->
        <el-dialog :title="title" :visible.sync="open" width="760px" append-to-body>
            <el-descriptions :column="2" border>
              <el-descriptions-item label="收款方" label-class-name="my-label" content-class-name="my-content1">{{form.objName}}</el-descriptions-item>
              <el-descriptions-item label="所属部门">{{user.deptName}}</el-descriptions-item>
              <el-descriptions-item label="钱包余额">{{Number(user.money)}}元</el-descriptions-item>
              <el-descriptions-item label="转账金额" :content-class-name="(Number(form.money) > Number(user.money) && form.type == 2) ? 'my-content2' : ''">{{Number(form.money)}}元</el-descriptions-item>
              <template>
                <el-descriptions-item label="真实姓名">{{user.payBankUser}}</el-descriptions-item>
                <el-descriptions-item label="手机号">{{user.payBankPhone}}</el-descriptions-item>
                <el-descriptions-item label="开户行">{{user.payBankName}}</el-descriptions-item>
                <el-descriptions-item label="银行卡号">{{user.payBankCard}}</el-descriptions-item>
              </template>
              <el-descriptions-item label="转账状态">
                <el-radio-group @input="changeState" v-model="transferStatus">
                  <el-radio label="2">已到账</el-radio>
                  <el-radio label="3">作废</el-radio>
                </el-radio-group>
              </el-descriptions-item>
            </el-descriptions>
            <template #footer>
                <div class="dialog-footer">
                    <el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
                    <el-button @click="cancel">取 消</el-button>
                </div>
            </template>
        </el-dialog>
    </div>
</template>

<script>
import {
  listMoneyItem,
  getMoneyItem,
  delMoneyItem,
  addMoneyItem,
  updateMoneyItem,
  cashBankList, GetUserInfo, handleBankCash
} from '@/api/wallet/moneyItem'

    import Editor from "../../components/Editor";
import { getDept } from '@/api/system/dept'
    export default {
      name: "wallet",
      dicts: ['wallet_classify','wallet_state','wallet_type'],
      components: {Editor},
      data() {
        return {
          moneyItemList: [],
          open: false,
          buttonLoading: false,
          loading: true,
          showSearch: true,
          ids: [],
          single: true,
          multiple: true,
          total: 0,
          title: '',
          form: {},
          queryParams: {
            pageNum: 1,
            pageSize: 10,
            objId: undefined,
            title: undefined,
            type: undefined,
            classify: undefined,
            state: undefined,
            relationId: undefined,
            orderByColumn: 'createTime',
            isAsc: 'desc',
          },
          rules: {
            itemId: [
              { required: true, message: "明细ID不能为空", trigger: "blur" }
            ],
          },
          user: {},
          transferStatus: undefined
        }
      },
      created() {
        this.getList();
      },
      methods: {
        /** 查询钱包明细列表 */
        getList() {
          this.loading = true;
          cashBankList(this.queryParams).then(response => {
            this.moneyItemList = response.rows;
            this.total = response.total;
            this.loading = false;
          });
        },
        changeState(value) {
          console.log(value)
          this.transferStatus = value
        },
        // 取消按钮
        cancel() {
          this.open = false;
          this.reset();
        },
        // 表单重置
        reset() {
          this.form = {
            itemId: null,
            objId: null,
            title: null,
            content: null,
            type: null,
            classify: null,
            money: null,
            createTime: null,
            state: null,
            relationId: null
          };
          this.resetForm("moneyItemRef");
        },
        /** 搜索按钮操作 */
        handleQuery() {
          this.queryParams.pageNum = 1;
          this.getList();
        },
        /** 重置按钮操作 */
        resetQuery() {
          this.resetForm("queryRef");
          this.handleQuery();
        },
        /** 修改按钮操作 */
        handleUpdate(row) {
          this.loading = true
          this.reset();
          const itemId = row.itemId || this.ids
          getMoneyItem(itemId).then(response => {
            this.loading = false;
            this.form = response.data;
            if (this.form.objType == 1) {
              // 转账到个人
              GetUserInfo({userId: this.form.objId }).then(res => {
                console.log(res, '对对对')
                this.user = res.data
              })
            } else {
              getDept(this.form.objId).then(res => {
                res.data.deptInfo.money = res.data.money
                this.user = res.data.deptInfo
              })
            }
            this.open = true;
            this.title = "处理转账";
          });
        },
        /** 提交按钮 */
        submitForm() {
          console.log(this.transferStatus,this.form)
          if (this.transferStatus) {
            this.buttonLoading = true;
            const data = {
              itemId: this.form.itemId,
              state: this.transferStatus
            }
            handleBankCash(data).then(response=> {
              this.$modal.msgSuccess("确认成功");
              this.open = false;
              this.transferStatus = undefined
              this.getList();
            }).finally(() => {
              this.buttonLoading = false;
            });
          }
        },
        /** 导出按钮操作 */
        handleExport() {
          this.download('web/moneyItem/export', {
            ...this.queryParams
          }, `moneyItem_${new Date().getTime()}.xlsx`)
        }
      }
    }
</script>
<style>
.my-content {
  color: red
}
</style>
